<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="livcos.org/ns/doc"
  xmlns:c="livcos.org/ns/cosmos"
  xmlns:f="livcos.org/ns/xslt/function"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="doc c f">

  <xsl:import href="../base.xsl" />

  <xsl:import href="default.xsl" />
  <xsl:import href="history.xsl" />
  <xsl:import href="outline.xsl" />
  <xsl:import href="image.xsl" />
  <xsl:import href="list.xsl" />
  <xsl:import href="table.xsl" />
  <xsl:import href="embedding.xsl" />
  <xsl:import href="link.xsl" />
	<xsl:import href="markup.xsl" />
	<xsl:import href="diagram.xsl" />
	
  <xsl:param name="incl-toc" select="'1'"/>
  <xsl:param name="incl-history" select="'1'"/>
  <xsl:param name="incl-tools" select="'1'"/>
  <xsl:param name="incl-editor" select="'1'"/>

	<xsl:variable name="readPlain" select="$symbian or $operaMini"/>
	
	<xsl:template match="/doc:document">
		<xsl:choose>
			<xsl:when test="$ie">
				<xsl:call-template name="no-IE-support"/>
			</xsl:when>
			<xsl:otherwise>
				<html id="{$callerObjId}">
					<xsl:apply-templates select="doc:head"/>
					<xsl:apply-templates select="doc:body"/>
				</html>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
  <xsl:template match="doc:document/doc:head">
    <head>
      <title><xsl:value-of select="doc:title" /></title>
    	<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"/>
      <meta name="served" content="{current-dateTime()}"/>
      <xsl:call-template name="page_styles"/>
      <xsl:call-template name="page_scripts"/>
      <xsl:call-template name="page_head_extension"/>
      <xsl:if test="$readPlain">
        <link href="{$toRootPath}/livcos.org/web/css/readPlain.css" rel="stylesheet" type="text/css" />
      </xsl:if>
    </head>
  </xsl:template>
  
  <xsl:template name="page_styles">
    <link href="{$toRootPath}/livcos.org/web/css/styles.css" rel="stylesheet" type="text/css" />
  </xsl:template>
  
  <xsl:template name="page_scripts">
    <xsl:choose>
      <xsl:when test="$readPlain">
      </xsl:when>
      <xsl:when test="$incl-editor = '1'">
				<script type="text/javascript" src="{$toRootPath}/livcos.org/web/script/scripts.js"><xsl:comment> </xsl:comment></script>
      </xsl:when>
      <xsl:otherwise>
      	<script type="text/javascript" src="{$toRootPath}/livcos.org/web/script/util.js"><xsl:comment> </xsl:comment></script>
      	<script type="text/javascript" src="{$toRootPath}/livcos.org/web/script/E.js"><xsl:comment> </xsl:comment></script>
      	<script type="text/javascript" src="{$toRootPath}/livcos.org/web/script/init.js"><xsl:comment> </xsl:comment></script>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template name="page_head_extension">
  </xsl:template>
  
  <xsl:template match="doc:document/doc:body">
    <body>
      <div id="{f:object-id(.)}" class="contentPanel">
        <div class="content">
          <xsl:apply-templates select="../doc:head/doc:context"/>
          <xsl:apply-templates select="../doc:head/doc:title"/>
          <xsl:if test="$incl-toc = '1'">
            <xsl:call-template name="toc"/>
          </xsl:if>
          <xsl:if test="$incl-history = '1'">
            <xsl:apply-templates select="../doc:history"/>
          </xsl:if>
          <xsl:apply-templates select="*"/>
          <xsl:if test="$incl-tools = '1'">
            <p>&#160;</p>
            <xsl:call-template name="tools"/>
          </xsl:if>
        </div>
      </div>
    </body>
  </xsl:template>

  <xsl:template name="toc">
    <div class="toc">
      <xsl:apply-templates select="doc:chapter" mode="toc"/>
    </div>
  </xsl:template>

  <xsl:template name="tools">
    <div class="tools">
      <a href="{f:object-name(.)}.pdf">
        <img src="{f:caller-uri('/livcos.org/web', 'img/pdf.png')}" border="0" />
      </a>
    </div>
  </xsl:template>

  <xsl:template match="doc:chapter" mode="toc">
    <p id="{@id}~1" onclick="if (!Doc().inEditMode) location.hash = '#{@id}'">
      <xsl:number level="multiple" count="doc:chapter" format="1.1"/>
      <xsl:text> </xsl:text>
			<span class="inlineEdit" title="title">
				<xsl:value-of select="doc:title"/>
			</span>
    </p>
    <xsl:apply-templates select="doc:chapter" mode="toc"/>
  </xsl:template>

  <xsl:template match="doc:document/doc:head/doc:context">
  	<p class="context"><span class="inlineEdit" title="head/context"><xsl:apply-templates/></span></p>
  </xsl:template>

  <xsl:template match="doc:document/doc:head/doc:title">
  	<p class="title"><span class="inlineEdit" title="head/title"><xsl:apply-templates/></span></p>
  </xsl:template>

</xsl:stylesheet>
